package cn.iocoder.yudao.module.game.controller.admin.withdrawalAccount;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.game.controller.admin.withdrawalAccount.vo.*;
import cn.iocoder.yudao.module.game.dal.dataobject.withdrawalAccount.WithdrawalAccountDO;
import cn.iocoder.yudao.module.game.service.withdrawalAccount.WithdrawalAccountService;

@Tag(name = "管理后台 - 提款账号")
@RestController
@RequestMapping("/game/withdrawal-account")
@Validated
public class WithdrawalAccountController {

    @Resource
    private WithdrawalAccountService withdrawalAccountService;

    @PostMapping("/create")
    @Operation(summary = "创建提款账号")
    @PreAuthorize("@ss.hasPermission('game:withdrawal-account:create')")
    public CommonResult<Long> createWithdrawalAccount(@Valid @RequestBody WithdrawalAccountSaveReqVO createReqVO) {
        return success(withdrawalAccountService.createWithdrawalAccount(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新提款账号")
    @PreAuthorize("@ss.hasPermission('game:withdrawal-account:update')")
    public CommonResult<Boolean> updateWithdrawalAccount(@Valid @RequestBody WithdrawalAccountSaveReqVO updateReqVO) {
        withdrawalAccountService.updateWithdrawalAccount(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除提款账号")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('game:withdrawal-account:delete')")
    public CommonResult<Boolean> deleteWithdrawalAccount(@RequestParam("id") Long id) {
        withdrawalAccountService.deleteWithdrawalAccount(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得提款账号")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('game:withdrawal-account:query')")
    public CommonResult<WithdrawalAccountRespVO> getWithdrawalAccount(@RequestParam("id") Long id) {
        WithdrawalAccountDO withdrawalAccount = withdrawalAccountService.getWithdrawalAccount(id);
        return success(BeanUtils.toBean(withdrawalAccount, WithdrawalAccountRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得提款账号分页")
    @PreAuthorize("@ss.hasPermission('game:withdrawal-account:query')")
    public CommonResult<PageResult<WithdrawalAccountRespVO>> getWithdrawalAccountPage(@Valid WithdrawalAccountPageReqVO pageReqVO) {
        PageResult<WithdrawalAccountDO> pageResult = withdrawalAccountService.getWithdrawalAccountPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, WithdrawalAccountRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出提款账号 Excel")
    @PreAuthorize("@ss.hasPermission('game:withdrawal-account:export')")
    @OperateLog(type = EXPORT)
    public void exportWithdrawalAccountExcel(@Valid WithdrawalAccountPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<WithdrawalAccountDO> list = withdrawalAccountService.getWithdrawalAccountPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "提款账号.xls", "数据", WithdrawalAccountRespVO.class,
                        BeanUtils.toBean(list, WithdrawalAccountRespVO.class));
    }

}